package com.itboye.sunsun.adapter;

import java.util.List;

import com.itboye.sunsun.R;
import com.itboye.sunsun.beans.OrderBean;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ImageView;

public class OrderListViewAdapter extends BaseAdapter {

	private Context context;
	private List<OrderBean> list;

	public OrderListViewAdapter(Context context, List<OrderBean> list) {
		this.context = context;
		this.list = list;

	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return list.size();
	}

	@Override
	public Object getItem(int arg0) {
		// TODO Auto-generated method stub
		return list.get(arg0);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	// 不同的Item

	@Override
	public int getItemViewType(int position) {
		// TODO Auto-generated method stub
		return list.get(position).getType();
	}

	@Override
	public int getViewTypeCount() {
		// TODO Auto-generated method stub
		return 3;
	}

	final class ViewHolderPay {

		Button selectButton;

	}

	final class ViewHolderSend {

		Button selectButton;

	}

	final class ViewHolderReceive {

		Button selectButton;

	}
	final class ViewHolderSuccess {

		Button selectButton;

	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {

		ViewHolderPay holdPay = null;
		ViewHolderSend holdSend = null;
		ViewHolderReceive holdReceive = null;
		ViewHolderSuccess holdSuccess = null;
		int type = getItemViewType(position);
		if (convertView == null) {

			switch (type) {
			case 1:

				convertView = LayoutInflater.from(context).inflate(
						R.layout.order_listview_item_pay, null);
				holdPay = new ViewHolderPay();
				holdPay.selectButton = (Button) convertView
						.findViewById(R.id.contact);
				convertView.setTag(holdPay);
				break;
			case 2:
				convertView = LayoutInflater.from(context).inflate(
						R.layout.order_listview_item_send, null);
				holdSend = new ViewHolderSend();
				holdSend.selectButton = (Button) convertView
						.findViewById(R.id.contact);
				convertView.setTag(holdPay);
				break;
			case 3:

				//注释 by hbd 
				convertView = LayoutInflater.from(context).inflate(
						R.layout.order_listview_item_receive, null);
				holdReceive = new ViewHolderReceive();
				holdReceive.selectButton = (Button) convertView
						.findViewById(R.id.contact);
				convertView.setTag(holdPay);
				break;
			case 4:
				convertView = LayoutInflater.from(context).inflate(
						R.layout.order_listview_item_success, null);
				holdSuccess = new ViewHolderSuccess();
				holdSuccess.selectButton = (Button) convertView
						.findViewById(R.id.contact);
				convertView.setTag(holdPay);
				
			default:
				break;

			}

		} else {

			switch (type) {
			case 1:
				holdPay = (ViewHolderPay) convertView.getTag();
				break;
			case 2:
				holdSend = (ViewHolderSend) convertView.getTag();
				break;
			case 3:
				holdReceive = (ViewHolderReceive) convertView.getTag();
				break;
			case 4:
				holdSuccess = (ViewHolderSuccess) convertView.getTag();
				break;
			default:
				break;

			}
		}

		return convertView;
	}

}
